﻿// -----------------------------------------------------------------------
// <copyright file="PersonInfoMapper.cs" company="EPAM Systems">
////Copyright (c) EPAM Systems, 2012. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------

namespace MBOP.Website.Infrastructure.Mappers
{
	#region Usings

	using System;

	using MBOP.Core.DTO;
	using MBOP.Core.Entities.Common;
	using MBOP.Core.Entities.Library;
	using MBOP.Core.Interfaces.Services;
	using MBOP.Website.ViewModels.Tooltips;

	#endregion

	/// <summary>
	/// Provides mapping for person information.
	/// </summary>
	public class PersonInfoMapper
	{
		#region Private Fields

		/// <summary>
		/// Represents person information service.
		/// </summary>
		private IPersonInformationService _personInfoService;

		#endregion

		#region Constructors

		/// <summary>
		/// Initializes a new instance of the <see cref="PersonInfoMapper"/> class.
		/// </summary>
		/// <param name="personInfoService">The <see cref="IPersonInformationService"/> implementer.</param>
		public PersonInfoMapper(IPersonInformationService personInfoService)
		{
			this._personInfoService = personInfoService;
		}

		#endregion

		/// <summary>
		/// Maps person info to person info view model.
		/// </summary>
		/// <param name="personInfo">The person info</param>
		/// <returns>The person info view model</returns>
		public PersonInfoViewModel MapPersonInfo(PersonInfo personInfo)
		{
			PersonInfoViewModel personInfoViewModel = null;

			if (personInfo != null)
			{
				personInfoViewModel = new PersonInfoViewModel()
										{
											CommonName = personInfo.CommonName,
											Position = personInfo.Position,
											DeliveryOffice = personInfo.DeliveryOffice,
											City = personInfo.City,
											Country = personInfo.Country,
											Email = personInfo.Email,
											VOIPID = personInfo.VOIPID,
											Workstation = personInfo.Workstation
										};

				if (personInfo.Photo != null)
				{
					personInfoViewModel.PhotoID = personInfo.Photo.ID;
				}
			}

			return personInfoViewModel;
		}

		/// <summary>
		/// Maps book subscription to person time info view model.
		/// </summary>
		/// <param name="bookSubscription">The book subscription.</param>
		/// <param name="stateTime">The state time.</param>
		/// <returns>The person time info view model.</returns>
		public PersonTimeInfoViewModel MapPersonTimeInfo(BookSubscription bookSubscription, TimeSpan stateTime)
		{
			PersonTimeInfoViewModel personTimeInfoViewModel = null;

			if (bookSubscription != null)
			{
				PersonInfo personInfo = this._personInfoService.GetPersonInfo(bookSubscription.PersonID, PersonFindingType.ID, false);

				if (personInfo != null)
				{
					personTimeInfoViewModel = new PersonTimeInfoViewModel()
												{
													PersonCommonName = personInfo.CommonName,
													StateTime = stateTime,
													SubscriptionState = (SubscribeState)bookSubscription.State
												};
				}
			}

			return personTimeInfoViewModel;
		}
	}
}